package com.lengxf.pay.web.service;

import cn.hutool.core.map.MapUtil;
import com.lengxf.pay.common.enums.PayChannel;
import com.lengxf.pay.starter.parent.pay.ChannelConfig;
import com.lengxf.pay.starter.parent.pay.PayServiceConfigFinder;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * 提供一个demo数据
 * 获取支付配置的方法
 * By Lengxf 2023-11-03 10:27:25
 **/
@Service
public class InMemoryPayServiceConfigFinder implements PayServiceConfigFinder {

    private final static String icbcStr = """
            {"merId":"380360000201","appId":"11000000000000012303","notifyUrl":"http://b2tzni.natappfree.cc/api/v1/1/packBack","keyPublic":"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCMpjaWjngB4E3ATh+G1DVAmQnIpiPEFAEDqRfNGAVvvH35yDetqewKi0l7OEceTMN1C6NPym3zStvSoQayjYV+eIcZERkx31KhtFu9clZKgRTyPjdKMIth/wBtPKjL/5+PYalLdomM4ONthrPgnkN4x4R0+D4+EBpXo8gNiAFsNwIDAQAB","keyPrivate":"MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDmgzqN4nYOdUtqfVifjlIWEhPJTqNvxiW3MFnPZYxlHkAbBbJR/fbcewVkqx+pCe3sMRZGEO/ajYaoxxKdX0/Fm3rrpht7q8S+mQ9IW3OwyYbFs2XnwqTvJ24PYuP23x4IPotwQJjCPrJVpNJJz25b7zENTjIuHrKdp+sRIZhHM70/YjzZiZ1YXhUr3Bz0Q6yyjR17/2hLbfPJaLc8AxDdw3hmiJDIye8HajJrkjETXBBuykF3S3iqf/79LaYBz+AuuT+NDjq6hKVI77oNvW1oNL4v1IF/ij1RqnJ4kZobHzzHt30dGbyGSAqSC2kYhIv9AQt2mj7X+4ICGW52gHjDAgMBAAECggEBAN09tJR7d53W3ERf/BBf8881GIKNFHZyMr7JDFnveDmROCv3YrgpTac99+YwDBoc6ptYXa1wEhWs4kLZlrcuxIy/9tF3w0cGjLX2h+GFzNswAUd9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d8JSDGY/yYPRXsEzFiaD+LSg="}""";
    private final static String aliStr = """
            {"appId":"9021000131616908","sellerId":"2088102147948060","notifyUrl":"http://b2tzni.natappfree.cc/api/v1/2/packBack","keyPublic":"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAiaYNNTcrrpZg+MXyAH9Kj54dEriDMjPfNdzq/Ijm//FW3QR/Uc8E/9ynVjJHzMBiL+gpWvSLldhDj5OjsEqnbFMWm9squswkucKqsW1nRlO87VfPEDotugJC/K0GhUAIgI0LpJqH7m1lXzaKq0XXM0k5Yux1coQd0lPwN2SDYFLT436iQf0UAQylJPJGrktyonv1RbatImGNU1RBCpiQaINbjEOtdRpon+VJdimvbIvdLd0SI+oY7vlncJvz2aSGoUODUqhO0HiaeIYUM9jnhr9uUyMdowCvsbmFAsq9j5o54kMSkRUJWOI6EXIRxfyK78FoubuqUjdF+8C6Sq2VQQIDAQAB","keyPrivate":"MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDEjYawpzek0ahIWcAyt+BWb/sfQhgcPRmS91sFdyFxH0xOOZ3OLWE/aFT8vZbaAHgZMQxppVGm6575BtJA9UX2RPxDvv/zqmxZe+cPKzIgaXGzCq0fAz/JooW5iqtnHDemtTaYznPdke0Ljmttsq2mmCe7EK8WVFe+wipne6VFte+1rstOajZlFpmTFcoYljN8gC4LYCAcd+Ub0K8nK2CjK5YKjZdLdDy3nn9J2FI+G0KNZ+6W6+Q8lRCshqHWv/22JNBTGaXtOQ46078BqbXT7leZYJ9Sd/IJfNpyuS9j0mQJx0W+w9B2EqMGWB9k6yU1qruwPm0h+Cqrclr3BuglAgMBAAECggEBAMD74GI0XMsEW4FmNfLWXXshCeTgBUI8r46ANauBE6G5RDeOFKYqIlCahM9+6s1zJng9k11rR2dn8ze4/dlvuVia1UFDGJXLIAUgRXa8R8RRI6TSd7Z6fzffzgKl57MennmddVTFaDgFnkP5evtDM4Ld5CykrfRzrY+Lnwzp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, Map<PayChannel, String>> config_map = new HashMap<>() {
        {
            Map<PayChannel, String> config1 = new HashMap<>();
            config1.put(PayChannel.ICBC, icbcStr);
            put("1", config1);
        }

        {
            Map<PayChannel, String> config1 = new HashMap<>();
            config1.put(PayChannel.ALI, aliStr);
            put("2", config1);
        }
    };


    @Override
    public ChannelConfig find(String id, Map<String, String> attr) {
        Map<PayChannel, String> configMap = config_map.get(id);
        if (MapUtil.isEmpty(configMap)) {
            throw new RuntimeException("未找到对应配置");
        }
        //每次支付的时候 必然只有最终一种支付方式选择
        //如果有多种方式 则根据业务进行过滤
        Map.Entry<PayChannel, String> entry = configMap.entrySet().stream().toList().get(0);
        return new ChannelConfig(entry.getKey(), entry.getValue());
    }

}
